package com.ludomancy.spaceopera.entities;
import java.awt.Graphics;
import java.awt.Point;
import com.ludomancy.gamelib.Accumulator;
import com.ludomancy.gamelib.ImageAnimation;
import com.ludomancy.gamelib.Randomizer;
import com.ludomancy.spaceopera.Game;
import com.ludomancy.spaceopera.LandWorld;
import com.ludomancy.spaceopera.Player;


public class FireHazard extends Hazard
{	
	private ImageAnimation anim;
	private Accumulator timeToBlow = new Accumulator(Game.forTime(1000));
	private Accumulator hitter = new Accumulator(Game.forTime(30));

	public FireHazard(Point pos)
	{
		super(pos);
		z = ZFRONT;
		anim = ImageAnimation.create("fire.png", 24, 24, 2);
		width = (int) proj.screenToWorldX(anim.strip.frameWidth);
		// reduce the hit area
		height = (int) proj.screenToWorldY((anim.strip.frameHeight*2)/3);
	}
	
	public boolean isConsumed()
	{
		return timeToBlow.isDone() && anim.isOver();
	}
			
	public void paint(Graphics g, int x, int y)
	{
		if(timeToBlow.isDone())
		{
			anim.update();
			anim.paintCurrentFrame(g, x, y);			
		}
		else
		{
			anim.strip.paint(g, 0, x, y+Randomizer.getRandom(-1,1));
		}
	}
	
	public int[] getBitmask(int x, int y, int w, int h)
	{
		return anim.getBitmask(x, y, w, h);
	}
	
	public boolean update()
	{
		timeToBlow.update();
		if(timeToBlow.isDone())
		{
			anim.play();
		}
			
		return false;
	}
	
	public void onPlayerHit(Player player)
	{
		if(timeToBlow.isDone())
		{
			hitter.update();
			if(hitter.isDone())
			{
				player.hit(1);
				hitter.reset();
			}
		}
	}

	public int getType()
	{
		return LandWorld.HAZARD_VOLCANO;
	}
}
